package com.tuozixuan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tuozixuan.model.User;
import com.tuozixuan.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;

	@ResponseBody
	@GetMapping("/getUser")
	public User getUser() {
		System.out.println("獲取用戶信息Start");
		User user = userService.getUser();
		System.out.println("獲取用戶信息End user:" + user);
		return user;
	}
	
	@ResponseBody
	@GetMapping("/getUserCount")
	public int getUserCount() {
		System.out.println("獲取用戶數Start");
		int userCount = userService.getUserCount();
		System.out.println("獲取用戶數End userCount:" + userCount);
		return userCount;
	}
	
	@ResponseBody
	@GetMapping("/getUserById")
	public User getUserById(String id) {
		System.out.println("獲取用戶信息Start");
		User user = userService.getUserById(Long.valueOf(id));
		System.out.println("獲取用戶信息End user:" + user);
		return user;
	}
	
	@ResponseBody
	@GetMapping("/getUserByName")
	public User getUserByName(String name) {
		System.out.println("獲取用戶信息Start");
		User user = userService.getUserByName(name);
		System.out.println("獲取用戶信息End user:" + user);
		return user;
	}

}
